using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LAFDC.DataAccess;
using LAFDC.Logging;

namespace LAFDC.Web.UI
{
    public partial class FamilleEdition : System.Web.UI.Page
    {
        private string adh_previd;
        public static readonly string source = "FamilleEdition.aspx";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Request.Params.Count > 0)
            {
                adh_previd = this.Request.QueryString.Get("adh");
                if (!IsPostBack)
                {
                    LoadData(adh_previd);
                }
                else
                {
                    lblSubmit.Text = "<script type=\"text/javascript\">window.opener.location.reload()</script>";
                    lblSubmit.Text += "<script type=\"text/javascript\">window.close()</script>";
                }
            }
        }

        private void LoadData(string adhid)
        {
            FDCLogger.LogEvent("Le formulaire est en train de retrouver les informations existante", source, 4);
            ConnectionManager cn = new ConnectionManager();
            SqlConnection conn = cn.GetSqlConnection();
            SqlCommand tsql = conn.CreateCommand();
            tsql.CommandType = CommandType.StoredProcedure;

            SqlParameter param = tsql.Parameters.Add("@PREV_ID", SqlDbType.NVarChar);
            param.Value = adhid;
            
            try
            {
                FDCLogger.LogEvent("FAMILLE...", source, 4);
                tsql.CommandText = "spGetFAMILLE_byPrevID";
                conn.Open();
                FDCLogger.LogEvent("Execution de GetFamille_byPrevId", source, 4);
                using (SqlDataReader reader = tsql.ExecuteReader())
                {
                    int i = 0;
                    string CurRef = string.Empty;
                    string CurPos = string.Empty;
                    string CurNom = string.Empty;
                    string CurPrenom = string.Empty;
                    string CurSexe = string.Empty;
                    string CurAnniv = string.Empty;


                    while (reader.Read())
                    {
                        FDCLogger.LogEvent("Loading data in form, currently at iteration " + i.ToString(), source, 4);
                        i++;
                        CurRef = reader.GetValue(0).ToString();
                        CurPos = reader.GetValue(1).ToString();
                        CurNom = reader.GetValue(2).ToString();
                        CurPrenom = reader.GetValue(3).ToString();
                        CurSexe = reader.GetValue(4).ToString();
                        CurAnniv = reader.GetValue(5).ToString();

                        StringBuilder sb = new StringBuilder();
                        sb.Append("Ajout du membre de la famille #" + i.ToString());

                        sb.Append(", avec les valeurs (curref=" + CurRef);
                        sb.Append(" , curpos=" + CurPos);
                        sb.Append(" , curnom=" + CurNom);
                        sb.Append(" , curprenom=" + CurPrenom);
                        sb.Append(" , cursexe=" + CurSexe);
                        sb.Append(" , curanniv=" + CurAnniv + ").");

                        FDCLogger.LogEvent(sb.ToString(), source, 4);

                        #region // SWITCH (10 x)
                        switch (i)
                        {
                            case 1:
                                {
                                    lblFamRef1.Text = CurRef;
                                    listFamPos1.SelectedValue = CurPos;
                                    txtNom1.Text = CurNom;
                                    txtPrenom1.Text = CurPrenom;
                                    listFamSexe1.Text = CurSexe;
                                    txtANNIV1.Text = CurAnniv;
                                    break;
                                }
                            case 2:
                                {
                                    lblFamRef2.Text = CurRef;
                                    listFamPos2.SelectedValue = CurPos;
                                    txtNom2.Text = CurNom;
                                    txtPrenom2.Text = CurPrenom;
                                    listFamSexe2.Text = CurSexe;
                                    txtANNIV2.Text = CurAnniv;
                                    break;
                                }
                            case 3:
                                {
                                    lblFamRef3.Text = CurRef;
                                    listFamPos3.SelectedValue = CurPos;
                                    txtNom3.Text = CurNom;
                                    txtPrenom3.Text = CurPrenom;
                                    listFamSexe3.Text = CurSexe;
                                    txtANNIV3.Text = CurAnniv;
                                    break;
                                }
                            case 4:
                                {
                                    lblFamRef4.Text = CurRef;
                                    listFamPos4.SelectedValue = CurPos;
                                    txtNom4.Text = CurNom;
                                    txtPrenom4.Text = CurPrenom;
                                    listFamSexe4.Text = CurSexe;
                                    txtANNIV4.Text = CurAnniv;
                                    break;
                                }
                            case 5:
                                {
                                    lblFamRef5.Text = CurRef;
                                    listFamPos5.SelectedValue = CurPos;
                                    txtNom5.Text = CurNom;
                                    txtPrenom5.Text = CurPrenom;
                                    listFamSexe5.Text = CurSexe;
                                    txtANNIV5.Text = CurAnniv;
                                    break;
                                }
                            case 6:
                                {
                                    lblFamRef6.Text = CurRef;
                                    listFamPos6.SelectedValue = CurPos;
                                    txtNom6.Text = CurNom;
                                    txtPrenom6.Text = CurPrenom;
                                    listFamSexe6.Text = CurSexe;
                                    txtANNIV6.Text = CurAnniv;
                                    break;
                                }
                            case 7:
                                {
                                    lblFamRef7.Text = CurRef;
                                    listFamPos7.SelectedValue = CurPos;
                                    txtNom7.Text = CurNom;
                                    txtPrenom7.Text = CurPrenom;
                                    listFamSexe7.Text = CurSexe;
                                    txtANNIV7.Text = CurAnniv;
                                    break;
                                }
                            case 8:
                                {
                                    lblFamRef8.Text = CurRef;
                                    listFamPos8.SelectedValue = CurPos;
                                    txtNom8.Text = CurNom;
                                    txtPrenom8.Text = CurPrenom;
                                    listFamSexe8.Text = CurSexe;
                                    txtANNIV8.Text = CurAnniv;
                                    break;
                                }
                            case 9:
                                {
                                    lblFamRef9.Text = CurRef;
                                    listFamPos9.SelectedValue = CurPos;
                                    txtNom9.Text = CurNom;
                                    txtPrenom9.Text = CurPrenom;
                                    listFamSexe9.Text = CurSexe;
                                    txtANNIV9.Text = CurAnniv;
                                    break;
                                }
                            case 10:
                                {
                                    lblFamRef10.Text = CurRef;
                                    listFamPos10.SelectedValue = CurPos;
                                    txtNom10.Text = CurNom;
                                    txtPrenom10.Text = CurPrenom;
                                    listFamSexe10.Text = CurSexe;
                                    txtANNIV10.Text = CurAnniv;
                                    break;
                                }
                        }
                        #endregion

                        CurRef = string.Empty;
                        CurPos = string.Empty;
                        CurNom = string.Empty;
                        CurPrenom = string.Empty;
                        CurSexe = string.Empty;
                        CurAnniv = string.Empty;

                    }
                }

                conn.Close();
            }
            catch
            {
                FDCLogger.LogEvent("Major error occuring now!!!", source, 1);
            }

        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            FDCLogger.LogEvent("Enregistrement du formulaire initialisee pour adherent " + adh_previd, source, 4);
            // Gather modified information from page, load and display back
            string temp = string.Empty;

            if (this.IsPostBack)
            {
                foreach (string changedObject in FormChangeTracker.mChangedObjects)
                {
                    FDCLogger.LogEvent("Le formulaire a ete change pour la section " + changedObject, source, 4);
                }

                ConnectionManager cn = new ConnectionManager();
                SqlConnection conn = cn.GetSqlConnection();
                SqlCommand tsql = conn.CreateCommand();

                string PREV_ID = adh_previd;
                FDCLogger.LogEvent("Checking for registered changes in Famille control section", source, 3);
                foreach (string entry in FormChangeTracker.mChangedObjects)
                {
                    FDCLogger.LogEvent("Found registered change:" + entry, source, 4);
                }

                if (FormChangeTracker.mChangedObjects.Contains("FAMILLE"))
                {
                    bool isNewFamille = false;
                    int ctrlId = 0;

                    string familleId = string.Empty;
                    string famPosition = string.Empty;
                    string famNom = string.Empty;
                    string famPrenom = string.Empty;
                    string famSexe = string.Empty;
                    string famAnniv = string.Empty;

                    foreach (string familleCode in FormChangeTracker.mChangedFamille)
                    {
                        #region // CHECK NEW vs EXISTING RELATIVES
                        // BUG !!!! ADD LOGGING HERE - as control 1 doesn't seem to return existing reference (which should be there)
                        if (familleCode.StartsWith("New_"))
                        {
                            ctrlId = Convert.ToInt32(familleCode.TrimStart("New_".ToCharArray()));
                            FDCLogger.LogEvent("Found a new relative at control " + ctrlId.ToString(), source, 3);
                            isNewFamille = true;
                        }
                        else
                        {
                            temp = familleCode.Substring(familleCode.Length - 1);
                            ctrlId = Convert.ToInt32(temp);

                            // as well as the contact id;
                            familleId = familleCode.Remove(familleCode.Length - 2);
                            FDCLogger.LogEvent("Found an existing relative with id " + familleId.ToString() + " at control " + ctrlId.ToString(), source, 3);


                            isNewFamille = false;
                        }
                        #endregion

                        #region // Gather data from form
                        switch (ctrlId)
                        {
                            case 1:
                                {
                                    famPosition = listFamPos1.Text;
                                    famNom = txtNom1.Text;
                                    famPrenom = txtPrenom1.Text;
                                    famSexe = listFamSexe1.Text;
                                    famAnniv = txtANNIV1.Text;
                                    break;
                                }
                            case 2:
                                {
                                    famPosition = listFamPos2.Text;
                                    famNom = txtNom2.Text;
                                    famPrenom = txtPrenom2.Text;
                                    famSexe = listFamSexe2.Text;
                                    famAnniv = txtANNIV2.Text;
                                    break;
                                }
                            case 3:
                                {
                                    famPosition = listFamPos3.Text;
                                    famNom = txtNom3.Text;
                                    famPrenom = txtPrenom3.Text;
                                    famSexe = listFamSexe3.Text;
                                    famAnniv = txtANNIV3.Text;
                                    break;
                                }
                            case 4:
                                {
                                    famPosition = listFamPos4.Text;
                                    famNom = txtNom4.Text;
                                    famPrenom = txtPrenom4.Text;
                                    famSexe = listFamSexe4.Text;
                                    famAnniv = txtANNIV4.Text;
                                    break;
                                }
                            case 5:
                                {
                                    famPosition = listFamPos5.Text;
                                    famNom = txtNom5.Text;
                                    famPrenom = txtPrenom5.Text;
                                    famSexe = listFamSexe5.Text;
                                    famAnniv = txtANNIV5.Text;
                                    break;
                                }
                            case 6:
                                {
                                    famPosition = listFamPos6.Text;
                                    famNom = txtNom6.Text;
                                    famPrenom = txtPrenom6.Text;
                                    famSexe = listFamSexe6.Text;
                                    famAnniv = txtANNIV6.Text;
                                    break;
                                }
                            case 7:
                                {
                                    famPosition = listFamPos7.Text;
                                    famNom = txtNom7.Text;
                                    famPrenom = txtPrenom7.Text;
                                    famSexe = listFamSexe7.Text;
                                    famAnniv = txtANNIV7.Text;
                                    break;
                                }
                            case 8:
                                {
                                    famPosition = listFamPos8.Text;
                                    famNom = txtNom8.Text;
                                    famPrenom = txtPrenom8.Text;
                                    famSexe = listFamSexe8.Text;
                                    famAnniv = txtANNIV8.Text;
                                    break;
                                }
                            case 9:
                                {
                                    famPosition = listFamPos9.Text;
                                    famNom = txtNom9.Text;
                                    famPrenom = txtPrenom9.Text;
                                    famSexe = listFamSexe9.Text;
                                    famAnniv = txtANNIV9.Text;
                                    break;
                                }
                            case 10:
                                {
                                    famPosition = listFamPos10.Text;
                                    famNom = txtNom10.Text;
                                    famPrenom = txtPrenom10.Text;
                                    famSexe = listFamSexe10.Text;
                                    famAnniv = txtANNIV10.Text;
                                    break;
                                }


                        }
                        #endregion

                        #region // New Relative - insert
                        if (isNewFamille)
                        {
                            // Insert into personne
                            tsql.CommandType = CommandType.Text;
                            tsql.CommandText = @"insert into personne ([prev_id], [nom], [prenom], [civ-sexe], [sfam], [anniv]) values ('" + PREV_ID + "','" + famNom + "','" + famPrenom + "','" + famSexe + "','" + famPosition + "','" + famAnniv + "')";
                            FDCLogger.LogEvent("Preparing to insert relative with: " + tsql.CommandText, source, 3);
                            conn.Open();
                            tsql.ExecuteNonQuery();
                            conn.Close();
                        }
                        #endregion

                        #region // Existing relative - update
                        else
                        {
                            // Update personne
                            tsql.CommandType = CommandType.Text;
                            tsql.CommandText = @"update personne 
set nom='" + famNom + "', prenom = '" + famPrenom + "', [civ-sexe] = '" + famSexe + "', sfam = '" + famPosition + "', anniv = '" + famAnniv + "' where id = '" + familleId + "'";

                            FDCLogger.LogEvent("Preparing to update relative with: " + tsql.CommandText, source, 3);
                            conn.Open();
                            tsql.ExecuteNonQuery();
                            conn.Close();
                        }
                        #endregion

                        ctrlId = 101;
                        isNewFamille = false;
                        famPosition = string.Empty;
                        famNom = string.Empty;
                        famPrenom = string.Empty;
                        famSexe = string.Empty;
                        famAnniv = string.Empty;
                    }
                    FormChangeTracker.mChangedFamille.Clear();
                    FormChangeTracker.mChangedObjects.Remove("FAMILLE");
                }

            }

        }


        #region // FAMILLE 1 CHANGED
        protected void listFamPos1_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef1.Text == "")
            {
                lblFamRef1.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef1.Text + "_1");
        }

        protected void txtNom1_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef1.Text == "")
            {
                lblFamRef1.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef1.Text + "_1");
        }

        protected void txtPrenom1_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef1.Text == "")
            {
                lblFamRef1.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef1.Text + "_1");

        }

        protected void listFamSexe1_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef1.Text == "")
            {
                lblFamRef1.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef1.Text + "_1");

        }

        protected void txtANNIV1_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef1.Text == "")
            {
                lblFamRef1.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef1.Text + "_1");

        }
        #endregion

        #region // FAMILLE 2 CHANGED
        protected void listFamPos2_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef2.Text == "")
            {
                lblFamRef2.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef2.Text + "_2");
        }

        protected void txtNom2_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef2.Text == "")
            {
                lblFamRef2.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef2.Text + "_2");
        }

        protected void txtPrenom2_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef2.Text == "")
            {
                lblFamRef2.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef2.Text + "_2");

        }

        protected void listFamSexe2_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef2.Text == "")
            {
                lblFamRef2.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef2.Text + "_2");

        }

        protected void txtANNIV2_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef2.Text == "")
            {
                lblFamRef2.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef2.Text + "_2");

        }
        #endregion

        #region // FAMILLE 3 CHANGED
        protected void listFamPos3_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef3.Text == "")
            {
                lblFamRef3.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef3.Text + "_3");
        }

        protected void txtNom3_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef3.Text == "")
            {
                lblFamRef3.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef3.Text + "_3");
        }

        protected void txtPrenom3_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef3.Text == "")
            {
                lblFamRef3.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef3.Text + "_3");

        }

        protected void listFamSexe3_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef3.Text == "")
            {
                lblFamRef3.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef3.Text + "_3");

        }

        protected void txtANNIV3_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef3.Text == "")
            {
                lblFamRef3.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef3.Text + "_3");

        }
        #endregion

        #region // FAMILLE 4 CHANGED
        protected void listFamPos4_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef4.Text == "")
            {
                lblFamRef4.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef4.Text + "_4");
        }

        protected void txtNom4_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef4.Text == "")
            {
                lblFamRef4.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef4.Text + "_4");
        }

        protected void txtPrenom4_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef4.Text == "")
            {
                lblFamRef4.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef4.Text + "_4");

        }

        protected void listFamSexe4_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef4.Text == "")
            {
                lblFamRef4.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef4.Text + "_4");

        }

        protected void txtANNIV4_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef4.Text == "")
            {
                lblFamRef4.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef4.Text + "_4");

        }
        #endregion

        #region // FAMILLE 5 CHANGED
        protected void listFamPos5_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef5.Text == "")
            {
                lblFamRef5.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef5.Text + "_5");
        }

        protected void txtNom5_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef5.Text == "")
            {
                lblFamRef5.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef5.Text + "_5");
        }

        protected void txtPrenom5_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef5.Text == "")
            {
                lblFamRef5.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef5.Text + "_5");

        }

        protected void listFamSexe5_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef5.Text == "")
            {
                lblFamRef5.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef5.Text + "_5");

        }

        protected void txtANNIV5_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef5.Text == "")
            {
                lblFamRef5.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef5.Text + "_5");

        }

        #endregion

        #region // FAMILLE 6 CHANGED
        protected void listFamPos6_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef6.Text == "")
            {
                lblFamRef6.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef6.Text + "_6");
        }

        protected void txtNom6_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef6.Text == "")
            {
                lblFamRef6.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef6.Text + "_6");
        }

        protected void txtPrenom6_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef6.Text == "")
            {
                lblFamRef6.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef6.Text + "_6");

        }

        protected void listFamSexe6_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef6.Text == "")
            {
                lblFamRef6.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef6.Text + "_6");

        }

        protected void txtANNIV6_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef6.Text == "")
            {
                lblFamRef6.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef6.Text + "_6");

        }
        #endregion

        #region // FAMILLE 7 CHANGED
        protected void listFamPos7_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef7.Text == "")
            {
                lblFamRef7.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef7.Text + "_7");
        }

        protected void txtNom7_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef7.Text == "")
            {
                lblFamRef7.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef7.Text + "_7");
        }

        protected void txtPrenom7_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef7.Text == "")
            {
                lblFamRef7.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef7.Text + "_7");

        }

        protected void listFamSexe7_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef7.Text == "")
            {
                lblFamRef7.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef7.Text + "_7");

        }

        protected void txtANNIV7_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef7.Text == "")
            {
                lblFamRef7.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef7.Text + "_7");

        }
        #endregion

        #region // FAMILLE 8 CHANGED
        protected void listFamPos8_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef8.Text == "")
            {
                lblFamRef8.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef8.Text + "_8");
        }

        protected void txtNom8_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef8.Text == "")
            {
                lblFamRef8.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef8.Text + "_8");
        }

        protected void txtPrenom8_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef8.Text == "")
            {
                lblFamRef8.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef8.Text + "_8");

        }

        protected void listFamSexe8_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef8.Text == "")
            {
                lblFamRef8.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef8.Text + "_8");

        }

        protected void txtANNIV8_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef8.Text == "")
            {
                lblFamRef8.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef8.Text + "_8");

        }
        #endregion

        #region // FAMILLE 9 CHANGED
        protected void listFamPos9_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef9.Text == "")
            {
                lblFamRef9.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef9.Text + "_9");
        }

        protected void txtNom9_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef9.Text == "")
            {
                lblFamRef9.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef9.Text + "_9");
        }

        protected void txtPrenom9_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef9.Text == "")
            {
                lblFamRef9.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef9.Text + "_9");

        }

        protected void listFamSexe9_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef9.Text == "")
            {
                lblFamRef9.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef9.Text + "_9");

        }

        protected void txtANNIV9_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef9.Text == "")
            {
                lblFamRef9.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef9.Text + "_9");

        }
        #endregion

        #region // FAMILLE 10 CHANGED
        protected void listFamPos10_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef10.Text == "")
            {
                lblFamRef10.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef10.Text + "_10");
        }

        protected void txtNom10_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef10.Text == "")
            {
                lblFamRef10.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef10.Text + "_10");
        }

        protected void txtPrenom10_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef10.Text == "")
            {
                lblFamRef10.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef10.Text + "_10");

        }

        protected void listFamSexe10_SelectedIndexChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef10.Text == "")
            {
                lblFamRef10.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef10.Text + "_10");

        }

        protected void txtANNIV10_TextChanged(object sender, EventArgs e)
        {
            FormChangeTracker tracker = new FormChangeTracker();
            tracker.RegisterChange("FAMILLE");

            if (lblFamRef10.Text == "")
            {
                lblFamRef10.Text = "New";
            }

            tracker.RegisterFamilleChange(lblFamRef10.Text + "_10");

        }
        #endregion

    }
}
